package no1177;

import java.util.ArrayList;
import java.util.List;

public class ExampleNo1177 {
    public static void main(String[] args) {
        String s = "abcda";
        int[][] queries = {{3, 3, 0}, {1, 2, 0}, {0, 3, 1}, {0, 3, 2}, {0, 4, 1}};
        List<Boolean> list = new ExampleNo1177().canMakePaliQueries(s, queries);
        System.out.println(list.toString());
    }

    public List<Boolean> canMakePaliQueries(String s, int[][] queries) {
        char[] ca = s.toCharArray();
        int n = ca.length, sum = 1 << ca[0] - 97;
        int[] preSum = new int[n + 1];
        for (int i = 1; i < n; ) {
            preSum[i] = sum;
            sum ^= 1 << ca[i++] - 97;
        }
        preSum[n] = sum;
        List res = new ArrayList<Boolean>(queries.length);
        for (int[] q : queries) res.add(Integer.bitCount(preSum[q[1] + 1] ^ preSum[q[0]]) >> 1 <= q[2]);
        return res;
    }
}
